package com.giscloud.generator.service;

import com.giscloud.generator.entity.dto.AmpStaffDTO;
import com.giscloud.generator.entity.vo.AmpStaffVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @Author:giscloud
 * @Description:
 * @Date: 16:04 2019/9/3
 * @Modified By:
 */
@Service
public class AmpStaffService {
    @Value("${giscloud.login.name:admin}")
    private String name;
    @Value("${giscloud.login.salt:3123713892282118}")
    private String salt;
    @Value("${giscloud.login.password:721e99d8c79c82475b320f4674b056e2489561303bb0a55e}")
    private String password;

    public AmpStaffVO getAmpStaffByCondition(AmpStaffDTO ampStaffDTO) {
        String[] names = name.split(",");
        boolean find = false;
        for (String nm : names) {
            if(nm.equals(ampStaffDTO.getLoginName())){
                find = true;
                break;
            }
        }
        if(find) {
            AmpStaffVO ampStaffVO = new AmpStaffVO();
            ampStaffVO.setOrgId(1L);
            ampStaffVO.setOrgName("部门");
            ampStaffVO.setRoleCode("roleCode");
            ampStaffVO.setStatusCd(1);
            ampStaffVO.setLoginName(ampStaffDTO.getLoginName());
            ampStaffVO.setPassword(password);
            ampStaffVO.setSaltValue(salt);
            if("admin".equals(ampStaffDTO.getLoginName())){
                ampStaffVO.setStaffId(0L);
                ampStaffVO.setRoleId(1L);
                ampStaffVO.setRoleName("管理员");
                ampStaffVO.setStaffName("管理员");
            }else{
                ampStaffVO.setStaffId(Long.parseLong(ampStaffDTO.getLoginName()));
                ampStaffVO.setRoleId(2L);
                ampStaffVO.setRoleName("普通角色");
                ampStaffVO.setStaffName("普通用户");
            }
            return ampStaffVO;
        }else{
            return null;
        }
    }
}
